package simpleftp.server;

import java.net.ServerSocket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Simple serveur TCP creant des thread pour gerer chaque connexion client.
 * 
 * @author lom
 */
public class FTPServerMain extends Thread {

	/**
	 * Port d'ecoute.
	 */
	public static final int PORT = 7802;
	private static ServerSocket socketaccueil;
	
	private FTPServer svr;
	public static void main(String argv[]) throws Exception 
	{
		final int poolSize = (int)((Runtime.getRuntime().availableProcessors()) / (0.1));
		final ExecutorService executorPool = Executors.newFixedThreadPool(poolSize);
		
			try {
				socketaccueil = new ServerSocket(PORT);
				System.out.println("Server up and running.");
				FTPServer.setDebug(true);
				while (true) {
					FTPServer server = new FTPServer(socketaccueil.accept());
					executorPool.submit(server);
				}
			} finally {
				if (socketaccueil != null) {
					socketaccueil.close();
				}
			}
		
	}
	public void run() {
		svr.call();
	}
	public FTPServerMain(FTPServer s) {
		svr = s;
	}
}
